package com.bruce.algorithm.search;

/**
 * 二分查找
 * <br>CreateDate  2021/11/05 12:21:11
 *
 * @author luotuan
 * @version 1.0.0
 */
public class BinarySearch {
    public static void main(String[] args) {
        int[] a = new int[]{2,3,5,10,13,22};
        System.out.println(search(a,0,a.length-1,23));
    }
    public static int search(int[] a,int low,int high,int value){
        if(low>high){
            return -1;
        }
        int mid = low+((high-low)>>1);
        while (low<=high){
            if(a[mid] == value){
                return mid;
            }else if(a[mid] >value){
                return search(a,low,mid-1,value);
            }else {
                return search(a,mid+1,high,value);
            }
        }
        return -1;
    }
}
